package com.yanqu.road.server.manger.activity.dafuweng.event;

import com.yanqu.road.entity.activity.dafuweng.DFWEvent;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eItemId;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.dafuweng.building.BaseDFWBuilding;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;

/**
 * @Author wpj
 * @Date 2021/1/7
 */
public class DFWStartRewardEvent extends BaseDFWEvent {

    public DFWStartRewardEvent(BaseDFWBuilding baseDFWBuilding, DFWEvent dfwEvent) {
        super(baseDFWBuilding, dfwEvent);
    }

    @Override
    public void doEvent() {
        Property property = PropertyHelper.parseStringToProperty(dfwEvent.getRewards());
        baseDFWBuilding.getPlayer().getModule(CurrencyModule.class).addCurrency(property, eLogMoneyType.DaFuWeng, eLogMoneyType.DaFuWengStartRewardEvent);
        int golden = property.getCountByGoodsId(eItemId.DFW_GOLDEN.getValue()).intValue();
        if (golden > 0) {
            userData.setGoldScore(userData.getGoldScore() + golden);
            baseDFWBuilding.getPlayer().notifyListener(eGamePlayerEventType.DaFuWengScoreRank.getValue(), userData.getGoldScore());
            baseDFWBuilding.getPlayer().notifyListener(eGamePlayerEventType.DaFuWengUnionScoreRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_NORMAL, BigInteger.valueOf(userData.getGoldScore()), baseDFWBuilding.getUnionUid()));
        }
        reward = dfwEvent.getRewards();
    }
}
